package com.tdg.qywx.utils;

import java.util.Calendar;
import java.util.Date;

/**
 * 通用工具类
 */
public class publicUtil {

    public static String getGdh1(String gdh){
        if(!gdh.contains("-")){
            return gdh;
        }
        String arr[] =  gdh.split("-");
        String gdh1 = arr[0];
        return gdh1;
    }

    /**
     * 判断当前时间是否在[startTime, endTime]区间，注意时间格式要一致
     * @param nowTime   当前时间
     * @param startTime 开始时间
     * @param endTime   结束时间
     * @return
     */
    public static boolean isEffectiveDate(Date nowTime, Date startTime, Date endTime) {
        if (nowTime.getTime() == startTime.getTime()
                || nowTime.getTime() == endTime.getTime()) {
            return false;
        }

        Calendar date = Calendar.getInstance();
        date.setTime(nowTime);

        Calendar begin = Calendar.getInstance();
        begin.setTime(startTime);

        Calendar end = Calendar.getInstance();
        end.setTime(endTime);

        if (date.after(begin) && date.before(end)) {
            return true;
        } else {
            return false;
        }
    }
}
